﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;


namespace GameNodeProgramm
{
    class Drawer
    {
        private readonly char frameChar;

        public Drawer(char frameChar)
        {
            this.frameChar = frameChar;
        }

        public void DrawNode(ConsoleNode node)
        {
            DrawGameNode(node);
            ClearGameNode(node);
        }

        public void DrawGameNode(ConsoleNode node)
        {
            Console.ForegroundColor = node.NodeColor;
            Console.SetCursorPosition(node.X, node.Y);
            Console.WriteLine(node.Symbol);
            Console.ForegroundColor = ConsoleColor.White;
        }

        public void ClearGameNode(ConsoleNode node)
        {
            Console.SetCursorPosition(node.X, node.Y);
            Console.WriteLine(' ');
        }

        public void DraweGameFieldFrame(GameField field)
        {
            int yPosition = field.StartY-1;
            int xPosition = field.StartX-1;
            for (int i = 0; i < field.Height+2; i++)
            {
                Console.SetCursorPosition(xPosition, yPosition);
                for (int j = 0; j < field.Width+2; j++)
                {
                    if (i == 0 || i == field.Height +1)
                    {
                        Console.Write(frameChar);
                    }
                    else if (j == 0 || j == field.Width +1)
                    {
                        Console.Write(frameChar);
                    }
                    else
                    {
                        Console.Write(' ');
                    }
                }
                Console.WriteLine();
                Console.SetCursorPosition(field.StartX,++yPosition);
            }
        }
    }
}
